package net.lab1024.smartadmin.module.business.engineExternalCharacteristic.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.dao.EngineExternalCharacteristicDao;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.dto.EngineExternalCharacteristicAddDTO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.dto.EngineExternalCharacteristicUpdateDTO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.dto.EngineExternalCharacteristicQueryDTO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.entity.EngineExternalCharacteristicEntity;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.vo.EngineExternalCharacteristicVO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.vo.EngineExternalCharacteristicExcelVO;
import net.lab1024.smartadmin.util.SmartPageUtil;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 发动机外特性曲线 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 发动机外特性曲线
 * @copyright (c)  发动机外特性曲线Inc. All rights reserved.
 * @date 2021-11-07 11:15:38
 * @since JDK1.8
 */
@Service
public class EngineExternalCharacteristicService {

    @Autowired
    private EngineExternalCharacteristicDao engineExternalCharacteristicDao;

    /**
     * 根据id查询
     */
    public EngineExternalCharacteristicEntity getById(Long id){
        return  engineExternalCharacteristicDao.selectById(id);
    }

    public EngineExternalCharacteristicEntity getByEngineId(Long id){
        LambdaQueryWrapper<EngineExternalCharacteristicEntity> queryWrapper = new LambdaQueryWrapper<EngineExternalCharacteristicEntity>();
        queryWrapper.eq(EngineExternalCharacteristicEntity::getEngineId, id);
        return engineExternalCharacteristicDao.selectOne(queryWrapper);
    }

    /**
     * 分页查询
     * @author wuhq
     * @date 2021-11-07 11:15:38
     */
    public ResponseDTO<PageResultDTO<EngineExternalCharacteristicVO>> queryByPage(EngineExternalCharacteristicQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<EngineExternalCharacteristicVO> voList = engineExternalCharacteristicDao.queryByPage(page, queryDTO);
        PageResultDTO<EngineExternalCharacteristicVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wuhq
     * @date 2021-11-07 11:15:38
     */
    public ResponseDTO<String> add(EngineExternalCharacteristicAddDTO addDTO) {
        EngineExternalCharacteristicEntity entity = SmartBeanUtil.copy(addDTO, EngineExternalCharacteristicEntity.class);
        engineExternalCharacteristicDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wuhq
     * @date 2021-11-07 11:15:38
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(EngineExternalCharacteristicUpdateDTO updateDTO) {
        EngineExternalCharacteristicEntity entity = SmartBeanUtil.copy(updateDTO, EngineExternalCharacteristicEntity.class);
        engineExternalCharacteristicDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wuhq
     * @date 2021-11-07 11:15:38
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        engineExternalCharacteristicDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> delByEngineId(Long engineId) {
        engineExternalCharacteristicDao.delByEngineId(engineId);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wuhq
     * @date 2021-11-07 11:15:38
     */
    public List<EngineExternalCharacteristicExcelVO> queryAllExportData(EngineExternalCharacteristicQueryDTO queryDTO) {
        return engineExternalCharacteristicDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wuhq
     * @date 2021-11-07 11:15:38
     */
    public List<EngineExternalCharacteristicExcelVO> queryBatchExportData(List<Long> idList) {
        return engineExternalCharacteristicDao.queryBatchExportData(idList);
    }
}
